package com.demo.rydemo.d_dic_detail.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.demo.rydemo.d_dic_detail.entity.DDicDetail;
import com.demo.rydemo.d_dic_detail.service.IDDicDetailService;
import com.demo.rydemo.result.AjaxResult;
import com.demo.rydemo.result.CoreController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ry
 * @since 2020-08-28
 */
@Api(tags = "字典详情相关接口")
@RestController
@RequestMapping("/d_dic_detail/d-dic-detail")
public class DDicDetailController  extends CoreController {

    @Autowired
    AjaxResult ajaxResult;

    @Autowired
    IDDicDetailService idDicDetailService;


    @ApiOperation("获取字典详情列表")
    @GetMapping("/getDicDetailList")
    AjaxResult getDicDetailList(String dicId){
        QueryWrapper<DDicDetail> queryWrapper = new QueryWrapper();
        queryWrapper.eq("dic_id",dicId);

        List<DDicDetail> list = idDicDetailService.list(queryWrapper);

        return ajaxResult.success(list);
    }

    @ApiOperation("添加字典详情")
    @PostMapping("/addDicDetail")
    AjaxResult addDicDetail(@RequestBody DDicDetail dDicDetail){
        Boolean flag = false;
        dDicDetail.setCreateTime(new Date())
                .setDicDetailId(UUID.randomUUID().toString().replace("-",""))
                .setStatus("1");

        flag = idDicDetailService.save(dDicDetail);
        if (flag){
            return ajaxResult.success("添加成功");
        }
        return ajaxResult.error("操作失败，请联系管理员");
    }
}
